/*--------------------------------------------------------------------------+
| $import (url           // String  - Scripts location (i.e. http://.../a.js)
|         [, container] // Object  - Window with script loading capability
|         [, type]      // String  - Type of script (i.e. text/javascript)
|         [, defer]     // Boolean - Flag for delaying script processing
|         [, language]  // String  - Language script is written in.
|         [, title])    // String  - Title for loaded script
|+--------------------------------------------------------------------------+
| Loads external JavaScripts; used by Import.
*--------------------------------------------------------------------------*/
$import = function(url, container, type, defer, language, title)
{
  // verify / attain container
  if(container == undefined || container == null) container = this;

  // setup container
  if(typeof container.write == "undefined")
	 if(typeof container.document != "undefined")
		container = container.document;
	 else throw "Invalid container. Unable to load [" + url + "]";

  // no type set
  if(type == undefined || type == null)
  {
	 type = '';

	 // no language so set default type
	 if(language == undefined || language == null)
	 {
		language = undefined;
		type = "text/javascript";
	 }
  }

  // set default language
  if(language == undefined || language == null) language = "JavaScript";

  // set title
  if(title == undefined || title == null) title = '';

  // set defer
  if(defer == undefined) defer = false;

  // build the script object
  var script = container.createElement("script");
  script.defer = defer;
  script.language = language;
  script.title = title;
  script.type = type;
  script.src = url;

  // dynamically load the script via it's container
  var head = container.getElementsByTagName("head")[0];
  head.appendChild(script);
}

/*--------------------------------------------------------------------------*/
function fireOnload(fn) {
  // DOM
	if(window.addEventListener) {
		window.addEventListener("load", fn, false);
	}
  // IE
	else if(window.attachEvent){
		window.attachEvent("onload", fn);
	}
  // Mac IE
	else {
		var oldFp = (document.onreadystatechange != null) ?
			document.onreadystatechange : function() {};

		document.onreadystatechange = function() {
			if(document.readyState == "interactive") {
				oldFp();
				fn();
			}
		};
	}
}